<!DOCTYPE html>
<html>
  <head>
    <title>Luigi Mock Identity Provider</title>
  </head>
  <body>
    Logging out...
    <script>
      var allPossibilitiesOfHashSlashes = '([^/?=&]+)(=([^&]*))?';

      var getQueryParams = function(uri) {
        var hashParams = {};
        uri.replace(new RegExp(allPossibilitiesOfHashSlashes, 'g'), function(
          $0,
          $1,
          $2,
          $3
        ) {
          hashParams[$1] = $3;
        });
        return hashParams;
      };

      window.onload = function() {
        var redirectTo;
        try {
          var url = new URL(window.location.href);
          var post_logout_redirect_uri = url.searchParams.get('post_logout_redirect_uri');
          redirectTo = post_logout_redirect_uri;

          var error = url.searchParams.get('error');
          var errorDescription = url.searchParams.get('errorDescription');
          if (error) {
            redirectTo = redirectTo + '?error=' + error;
            if (errorDescription) {
              redirectTo += '&errorDescription=' + errorDescription;
            }
          }
        } catch (error) {
          redirectTo = decodeURIComponent(
            window.location.href.match(/post_logout_redirect_uri=(.*?)(&|$)/)[1]
          );
        }
        window.location.href = redirectTo;
      };
    </script>
  </body>
</html>
